#include <vector>
#include <string>
#include <iostream>
using std::vector;
using std::string;
class Solution
{
public:
    int longestValidParentheses(string s)
    {
        if (s.size() == 0) return 0;
        vector<int> dp(s.size(), 0);
        int maxLen = 0;
        for (int i = 1; i < s.size(); i++) {
            if (s[i] == '(') {
                dp[i] = 0;
            }
            else {
                if (s[i-1] == '(' && i > 1) dp[i] = dp[i-2] + 2;
                else {
                    auto idx = i - dp[i-1] - 1;
                    auto offset = (idx > 0) ? dp[idx-1] : 0;
                    dp[i] = (idx >= 0 && s[idx] == '(') ? dp[i-1] + 2 + offset : 0;
                }
            }
            maxLen = (maxLen > dp[i]) ? maxLen : dp[i];
            //std::cout << maxLen << " dp[" << i << "] is " << dp[i] << "\n";
        }
        return maxLen;
    }
};

int main()
{
    string input;
    std::cin >> input;
    auto maxLen = Solution().longestValidParentheses(input);
    std::cout << maxLen;
}